using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region AssignmentDefination

	/// <summary>
	/// AssignmentDefination object for NHibernate mapped table 'AssignmentDefination'.
	/// </summary>
	[Serializable]
	public class AssignmentDefination : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected int _projectType;
		protected string _assignmentType;
		protected Role _roleId;
		protected Step _stepId;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public AssignmentDefination() { }

		public AssignmentDefination( int projectType, string assignmentType, Role roleId, Step stepId )
		{
			this._projectType = projectType;
			this._assignmentType = assignmentType;
			this._roleId = roleId;
			this._stepId = stepId;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public int ProjectType
		{
			get { return _projectType; }
			set { _projectType = value; }
		}

		public string AssignmentType
		{
			get { return _assignmentType; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for AssignmentType", value, value.ToString());
				_assignmentType = value;
			}
		}

		public Role RoleId
		{
			get { return _roleId; }
			set { _roleId = value; }
		}

		public Step StepId
		{
			get { return _stepId; }
			set { _stepId = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is AssignmentDefination))
				throw new InvalidCastException("This object is not of type AssignmentDefination");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((AssignmentDefination)obj).Id);
					break;
				case "ProjectType":
					relativeValue = this.ProjectType.CompareTo(((AssignmentDefination)obj).ProjectType);
					break;
				case "AssignmentType":
					relativeValue = this.AssignmentType.CompareTo(((AssignmentDefination)obj).AssignmentType);
					break;
                default:
                    goto case "Id";
			}
            if (AssignmentDefination.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
